package com.web.admin.web.base.log;

import com.blue.core.dict.HttpMethod;
import com.blue.core.dict.annotation.DictParser;
import com.blue.http.annotation.Http;
import com.blue.http.message.HttpRequest;
import com.blue.http.message.View;
import com.web.base.log.facade.UploadFacade;
import com.web.base.log.message.UploadRequest;
import com.web.base.log.message.UploadResponse;
import com.web.core.util.Const;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

/**
 * 上传文件日志控制器
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2017年11月21日
 */
@Controller("logUploadController")
@Http(url = "/base/log")
public class UploadController
{
	@Autowired
	private UploadFacade uploadFacade;
	
	private static DictParser parser = DictParser.getInstance();
	
	public UploadController()
	{
	}

	@Http(url = "/upload_list", method = HttpMethod.GET)
	public View listGet(HttpRequest request)
	{
		UploadRequest uploadRequest = request.getQueryObject(UploadRequest.class);
		return View.createBuilder().setView("/base/log/upload_list")
				.put("model", request)
				.put("page", uploadFacade.listPage(uploadRequest, Const.PAGE_START, Const.PAGE_SIZE))
				.put("map", parser.getStringMap())
				.build();
	}
	
	@Http(url = "/upload_list", method = HttpMethod.POST)
	public View listPost(HttpRequest request)
	{
		UploadRequest uploadRequest = request.getPostObject(UploadRequest.class);
		int start = request.getPostInt("start", Const.PAGE_START);
		return View.createBuilder().setView("/base/log/upload_list_grid")
				.put("page", uploadFacade.listPage(uploadRequest, start, Const.PAGE_SIZE))
				.build();
	}
	
	@Http(url = "/upload_get", method = HttpMethod.GET)
	public View get(HttpRequest request)
	{
		int id = request.getQueryInt("id", 0);
		UploadResponse response = null;
		if (id > 0)
		{
			response = uploadFacade.get(id);
		}
		return View.createBuilder().setView("/base/log/upload_get")
				.put("model", response == null ? new UploadResponse() : response)
				.put("map", parser.getStringMap())
				.build();
	}
	
	@Http(url = "/upload_test", method = HttpMethod.POST)
	public void save(HttpRequest request)
	{
		UploadRequest uploadRequest = request.getPostObject(UploadRequest.class);
		UploadResponse response = uploadFacade.add(uploadRequest);
	}

}
